package com.ujoku.service.impl;

import com.labillusion.core.database.base.mybatis.dao.BaseDao;
import com.labillusion.core.database.base.mybatis.service.base.impl.BaseServiceImpl;
import com.labillusion.core.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ujoku.domain.Store;
import com.ujoku.service.StoreService;
import com.ujoku.dao.StoreDao;

import java.util.List;
import java.util.stream.Collectors;


@Service
public class StoreServiceImpl extends BaseServiceImpl<Store> implements StoreService<Store> {

    @Autowired
    private StoreDao dao;

    @Override
    protected BaseDao<Store> getBaseDao() {
        return this.dao;
    }

    @Override
    public List<Store> getStores(String address) {
        List<Store> allStores = this.selectList();

        List<Store> storeList;
        if(StringUtils.hasText(address)){
            storeList = allStores.stream().filter(s->s.getProvince().equalsIgnoreCase(address) || address.equals(s.getCity())).collect(Collectors.toList());

        }else {
            storeList = allStores;
        }
        return storeList;
    }

}